package org.sbbs.app.license.webapp.action;

import java.util.ArrayList;

import org.sbbs.app.license.service.LicenseInfoManager;
import org.sbbs.base.search.PropertySearchBuilder;
import org.sbbs.base.webapp.action.BaseGridAction;

import com.googlecode.genericdao.search.Search;
import com.googlecode.genericdao.search.SearchResult;

public class LicenseInfoGridAction
    extends BaseGridAction {
    /**
     *
     */
    private static final long serialVersionUID = -3938015919352134327L;

    private LicenseInfoManager licenseInfoManager;

    private Long customerId;

    @Override
    public String gridPageList() {
        if ( customerId != null ) {
        Search search = PropertySearchBuilder.BuildSearch( getRequest() );
            search.addFilterEqual( "customerInfo.customerInfoId", customerId );
        SearchResult srt = this.licenseInfoManager.searchAndCount( search );
        this.setPageList( srt.getResult() );
        this.records = srt.getTotalCount();
        this.total = getTotlePage( records, search.getMaxResults() );
        this.page = search.getPage() + 1;
        }else{
            this.setPageList( new ArrayList(0) );
            this.records = 0;
            this.total = 0;
            this.page = 0;
        }
        return SUCCESS;
    }

    public LicenseInfoManager getLicenseInfoManager() {
        return licenseInfoManager;
    }

    public void setLicenseInfoManager( LicenseInfoManager licenseInfoManager ) {
        this.licenseInfoManager = licenseInfoManager;
    }

    public Long getCustomerId() {
        return customerId;
    }

    public void setCustomerId( Long customerId ) {
        this.customerId = customerId;
    }

}
